/**
 * 作者: wgx
 * 日期: 2024-11-01 15:24:28
 * 备注: 用户主线关卡信息表
 */
package com.motu.monstercity.server.game.userdata;

import com.motu.monstercity.server.game.commondata.fight.Stage;
import com.motu.monstercity.server.game.logic.FightBaseData;
import com.motu.vertx.module.utility.toolset.TimeUtils;
import io.vertx.core.json.JsonObject;

public class UserStage extends UserStageModel {
    public UserStage() {
        super();
    }

    public JsonObject insert() {
        putResetTime(TimeUtils.getCurTime());
        putMapId(1);
        putStageId(1);
        putNodeNum(0);
        putUnlockAreaId(1);
        return super.insert();
    }

    public void reset() {
        boolean isUpdate = false;
        if (!TimeUtils.isToday(getResetTime())) {
            putResetTime(TimeUtils.getCurTime());
            putGuardQuickNum(0);
            isUpdate = true;
        }
        if (isUpdate) {
            update();
        }
    }

    public long getStageProgress() {
        return mapId * 100L + stageId;
    }

    // 是否开启了卫兵挂机奖励功能
    public boolean isGuardRewardOpen() {
        if (getGuardRewardTime() > 0) {
            return true;
        } else {
            return false;
        }
    }

    // 获取已经通关的关卡，userstage记录的是当前要打的关卡（上一关卡就是已经通关的关卡）
    public Stage takeCompleteStage() {
        int lastMapId = 1;
        int lastStageId = 1;
        if (getStageId() > 1) {//
            lastMapId = getMapId();
            lastStageId = getStageId() - 1;
        } else if (getStageId() == 1 && getMapId() > 1) {
            lastMapId = getMapId() - 1;
            Stage stage = FightBaseData.getMaxStageByMapId(lastMapId);
            if (stage != null) {
                return stage;
            }
        }
        return FightBaseData.getStage(lastMapId, lastStageId);
    }
}
